<%-- 
    Document   : index
    Created on : 04-dic-2014, 11:52:06
    Author     : equipo_4
--%>

<%@page import="Conexion.Conexion"%>
<%@page import="java.util.List"%>
<%@page import="RRHH_MODELO.RHH_PROFESION"%>
<%@page import="java.util.StringTokenizer"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>BROKER</title>
         <script src="js/jquery-1.8.2.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div>
            <input type="text" value="" name="usr" placeholder="USUAIRO"/>
            <input type="password" value="" name="pass" placeholder="CONTRACEÑA"/>
            <button onclick="loguin();">INGRESAR</button>
            <span id="registro" onclick="ver_Registro();" style="display: none;">Registrarse</span>
            <span id="mensage" style="display: none; color: red;"></span><button id="reenviar" onclick="reenviar();" style="display: none;">REENVIAR</button>
        </div>
        <div style="display: none;" id="cont_registro">
            <form id="reg"  method="POST" enctype="multipart/form-data">
                <input type="text" name="ci" value="" placeholder="CI"/>
                <input type="hidden" name="evento" value="registro"/>
                <select name="depto">
                    <option value="1">SCZ</option>
                    <option value="2">BN</option>
                    <option value="3">PND</option>
                    <option value="4">TRJ</option>
                    <option value="5">CBBA</option>
                    <option value="6">SCR</option>
                    <option value="7">LPZ</option>
                    <option value="8">PT</option>
                    <option value="9">OR</option>
                </select><br>
                <input type="text" name="nombre1" value="" placeholder="PRIMER NOMBRE"/><br>
                <input type="text" name="nombre2" value="" placeholder="SEGUNDO NOMBRE"/><br>
                <input type="text" name="apepat" value="" placeholder="PRIMER APELLIDO"/><br>
                <input type="text" name="apemat" value="" placeholder="SEGUNDO APELLIDO"/><br>
                <input type="text" name="email" value="" placeholder="EMAIL"/><br>
                <input type="text" name="telf" value="" placeholder="TELEFONO"/><br>
                <select name="prof">         
                <%
                    Conexion con = new Conexion();
                    List<RHH_PROFESION> lista = new RHH_PROFESION(con).Todos();
                    for (int i = 0; i < lista.size(); i++) {
                       out.print("<option value='"+lista.get(i).getID()+"'>"+lista.get(i).getDESCRIPCION()+"</option>");
                    }
                %>                
                </select><br>
                <input type="number" value="" name="anos" placeholder="AÑOS EXPERIENCIA"/>
                <input type="file" name="curr" />
                <button onclick="insertar();">ACEPTAR</button>
                <button onclick="cancel();">CANCELAR</button>
            </form>
        </div>
            
        <script type="text/javascript">
            var url = "loguin";
            function reenviar()
            {
                var usr = $("input[name=usr]").val();
                $.post(url,{evento:"reenviarPass",usr:usr},function (response){
                     $("#mensage").css("color","black");
                     $("#mensage").text(response);
                     $("#mensage").css("display","block");
                     $("#registro").css("display","none");
                     cancel();
                });                 
            }

            function insertar()
            {                
                
                $("#reg").submit(function(e)
                {
                var formData = new FormData(this);
                 $.ajax({
                        url: url,
                        type: 'POST',
                        data:  formData,
                        mimeType:"multipart/form-data",
                        contentType: false,
                        cache: false,
                        processData:false,
                        success: function(response, textStatus, jqXHR)
                        {
                            if(response=="true")
                            {
                                $("#mensage").css("color","black");
                                $("#mensage").text("Su Contraceña fue enviada a "+email);
                                $("#mensage").css("display","block");
                                $("#registro").css("display","none");
                                cancel();
                            }
                            else
                            {
                                $("#mensage").css("color","black");
                                $("#mensage").text("ERROR EN LOS DATOS DE REGISTRO");
                                $("#mensage").css("display","block");
                                $("#registro").css("display","none");
                                cancel();
                            }
                        },
                        error: function(jqXHR, textStatus, errorThrown)
                        {
                            
                        }         
                    });
                    e.preventDefault(); //Prevent Default action.
                });      
            }
            
            function cancel()
            {
                 $("#cont_registro").css("display","none");
                 $("input").val("");
            }
            
            function ver_Registro()
            {
                $("#cont_registro").css("display","block");
            }
                       
            
            function loguin()
            {
                var usr = $("input[name=usr]").val();
                var pass = $("input[name=pass]").val();
                $.post(url,{evento:"logueo",usr:usr,pass:pass},function (response){
                    if(response=="true")
                    {
                        location.href="ppl.jsp";
                    }
                    if(response=="2")
                    {
                        $("#mensage").text("Contraceña Incorrecta");
                        $("#mensage").css("display","block");
                        $("#reenviar").css("display","block");
                        $("#registro").css("display","none");
                    }
                    if(response=="false")
                    {
                        $("#registro").css("display","block");
                        $("#mensage").css("display","none");
                    }                                        
                });
            }
            
            
        </script>
    </body>
</html>
